package com.neusoft.ysu.populationmanagement.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.neusoft.ysu.populationmanagement.constant.TabelDic;
import com.neusoft.ysu.populationmanagement.entity.CommonResult;
import com.neusoft.ysu.populationmanagement.vo.VOperator;
import com.neusoft.ysu.populationmanagement.mapper.VOperatorMapper;
import com.neusoft.ysu.populationmanagement.service.IVOperatorService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * VIEW 服务实现类
 * </p>
 *
 * @author jyl
 * @since 2025-06-18
 */
@Service
public class VOperatorServiceImpl extends ServiceImpl<VOperatorMapper, VOperator> implements IVOperatorService {

    @Autowired
    private VOperatorMapper operatorMapper;

    @Override
    public CommonResult login(String username, String password) {
        LambdaQueryWrapper<VOperator> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(VOperator::getUsername, username).eq(VOperator::getIsDelete, TabelDic.IS_DELETE_NO);
        List<VOperator> operators = operatorMapper.selectList(lambdaQueryWrapper);
        if (operators.size() <= 0) {
            return new CommonResult<>(401, "该用户被禁用或未注册", null);
        }
        if (!password.equals(operators.get(0).getPassword())) {
            return new CommonResult<>(401, "密码错误", null);
        }
        return new CommonResult<>(1, "登陆成功", operators.get(0));
    }
}
